package com.springboot.service.impl;

import com.springboot.mapper.GoodsMapper;
import com.springboot.mapper.UserMapper;
import com.springboot.model.Goods;
import com.springboot.model.User;
import com.springboot.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: TongRui乀
 * @Date: 2019/10/16 13:56
 * @description：
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public Goods getGoodsById(Integer id) {

        return this.goodsMapper.selectById(id);
    }

    @Override
    public User getUserById(Integer id) {

        return this.userMapper.selectById(id);
    }

    @Transactional(transactionManager = "secondaryDataSourceTransactionManager")
    @Override
    public void insertUser(User user) {

        User update = new User();

        update.setId(2);
        update.setPhone("22222222");

        this.userMapper.update(update);

        this.userMapper.insert(user);

        int a = 1 / 0;

    }

    @Transactional
    @Override
    public void insertGoods(Goods goods) {
        this.goodsMapper.insert(goods);
    }
}
